package com.project.service.service;

import com.project.service.bean.UserBean;
import com.project.service.dao.IUserDao;
import com.project.service.server.Request;
import com.project.service.server.Response;
import com.project.service.server.Servlet;
import com.project.service.util.DaoFactory;
import com.project.service.util.WebServlet;

import java.util.List;

/**
 * 查询所有业务组件
 */
@WebServlet("findAll")
public class FindAllService implements Servlet {
    /**用户持久组件*/
    private IUserDao dao = (IUserDao)DaoFactory.getDao("IUserDao");

    public void service(Request req, Response resp){
        List<UserBean> list =  dao.findAll();

        String str = "<table border='1' width='80%'>";
        str += "<thead><tr><th>用户名</th><th>密码</th><th>生日</th>" +
                "<th>操作</th></tr></thead>";

        str += "<tbody>";
        for(UserBean user : list){
            str += "<tr><td>"+user.getName()+"</td>" +
                    "<td>"+user.getPwd()+"</td>" +
                    "<td>"+user.getBirthday()+"</td>" +
                    "<td><a href='del?id="+user.getId()+"'>删除</a>" +
                    " <a href='findById?id="+user.getId()+"'>修改</a></td></tr>";
        }

        str += "</tbody></table>";

        resp.sendMessage(str);

    }
}
